<template>
  <div class="app-container">
    <el-row>
      <el-col :span="6">
        <el-select v-model="key" filterable allow-create default-first-option placeholder="请输入redis键名">
          <el-option v-for="item in keyList" :key="item.code" :label="item.name" :value="item.code"> </el-option>
        </el-select>
      </el-col>
      <el-col :span="4" style="margin-left: 20px">
        <el-button type="danger" @click="dialogVisible = true"><i class="el-icon-delete"></i>清理redis</el-button>
      </el-col>
    </el-row>
    <el-dialog title="是否确认清理" :visible.sync="dialogVisible" width="30%">
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="clearRedis()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
/** 工具类 */
import { deleteAction } from '@tapui/utils/http'
import { queryDataCode } from '@tapui/api/dataCode'
export default {
  name: 'redisDelete',
  data() {
    return {
      description: '基础字段信息-列表查询',
      urlPrefix: '/base/property/',
      url: {
        clearRedis: '/base/property/clearRedis'
      },
      key: '',
      keyList: [],
      dialogVisible: false
    }
  },
  methods: {
    clearRedis() {
      let paraMap = {
        rediskey: this.key
      }
      deleteAction(this.url.clearRedis, paraMap)
        .then((res) => {
          if (res.success) {
            this.$tap.message(res.message, 'success')
            this.dialogVisible = false
          } else {
            this.$tap.alert(res.message, 'warning')
          }
        })
        .catch((err) => {
          this.$tap.alert(err.message)
        })
    }
  },
  created() {
    queryDataCode({ itemCodes: 'RedisDefaultKey' }).then((res) => {
      this.keyList = res.result.RedisDefaultKey
    })
  }
}
</script>

<style scoped></style>
